
####################################
# differ for each OS 
INSTALL = $$INSTALL$$ 
INSTALL_DIROPT = $$INSTALL_DIROPT$$
INSTALL_OWNER = $$INSTALL_OWNER$$ ${USER}
PREFIX = $$PREFIX$$
PERM_BINARY = $$PERM_BINARY$$
PERMDIR = $$PERM_DIR$$
####################################
exec_PREFIX = ${PREFIX}
bindir = ${exec_PREFIX}/bin
etcdir = ${PREFIX}/etc
mandir = ${PREFIX}/man/man3
sharedir = ${PREFIX}/share
docdir = ${sharedir}/doc
libdir = ${PREFIX}/lib

####################################

NAME = libinclude.sh
VERSION = 1.0.0
SEARCHPATH = $(libdir)/$(NAME)

####################################
.PHONY : build

all: build

clean:
	@rm -f ${NAME}

distclean: clean
	@rm -f Makefile
	@rm -f $(NAME)-$(VERSION).tar.gz

install: build
	$(INSTALL) $(INSTALL_DIROPT) -d $(bindir)
	$(INSTALL) $(INSTALL_DIROPT) -d $(sharedir)/$(NAME)
	$(INSTALL) $(INSTALL_DIROPT) -d $(docdir)/$(NAME)
	$(INSTALL) $(INSTALL_DIROPT) -d $(libdir)/$(NAME)
	$(INSTALL) $(INSTALL_DIROPT) -d $(mandir)
	$(INSTALL) ${PERM_BINARY} ${INSTALL_OWNER} $(NAME) $(bindir)
	$(INSTALL) ${PERM_DIR} ${INSTALL_OWNER} lib/* $(libdir)/$(NAME)
	$(INSTALL) ${PERM_DIR} ${INSTALL_OWNER} README $(docdir)/$(NAME)
	$(INSTALL) ${PERM_DIR} ${INSTALL_OWNER} COPYING $(docdir)/$(NAME)
	$(INSTALL) ${PERM_DIR} ${INSTALL_OWNER} html $(docdir)/$(NAME)
	$(INSTALL) ${PERM_DIR} ${INSTALL_OWNER} libinclude.pdf $(docdir)/$(NAME)
	$(INSTALL) ${PERM_DIR} ${INSTALL_OWNER} share/* $(sharedir)/$(NAME)
	$(INSTALL) ${PERM_DIR} ${INSTALL_OWNER} man/libinclude.3 $(mandir)

uninstall:
	@rm -f $(bindir)/$(NAME)
	@rm -Rf $(sharedir)/$(NAME)
	@rm -Rf $(libdir)/$(NAME)
	@rm -f $(mandir)/libinclude.3

build: 
	@echo -n "#!/bin/sh" > ./$(NAME)
	@cat ./COPYING >> ./$(NAME)
	@cat src/$(NAME) | sed -e 's/[$$][$$]VERSION[$$][$$]/${VERSION}/' -e 's:[$$][$$]SEARCHPATH[$$][$$]:${SEARCHPATH}:' >> ./$(NAME)
	@chmod 755 ./$(NAME)

docs:
	make -C doc man
	make -C doc html
	make -C doc latexpdf

dist: docs
	@rm -rf $(NAME)-$(VERSION)
	@mkdir $(NAME)-$(VERSION)
	@cp -r COPYING CHANGELOG TODO configure Makefile.in doc/build/html doc/build/man doc/build/latex/libinclude.pdf lib share test src $(NAME)-$(VERSION)
	@rm -r $(NAME)-$(VERSION)/html/_sources $(NAME)-$(VERSION)/html/.buildinfo $(NAME)-$(VERSION)/html/objects.inv $(NAME)-$(VERSION)/html/index_pdf.html
	@sed -e 's/\.\. note::/Note:/' -e 's/\.\. .*//' doc/source/get_started.rst > $(NAME)-$(VERSION)/INSTALL
	@cp -r doc/source/manpage.rst $(NAME)-$(VERSION)/README
	@rm -rf $(NAME)-$(VERSION)/src/.svn
	@tar -cvzf $(NAME)-$(VERSION).tar.gz $(NAME)-$(VERSION)
	@rm -rf $(NAME)-$(VERSION)


